<template>
  <div class="gk-layout-container">
    <div class="gk-layout-header">
      <!--工具栏-->
      <div class="toolbar" style="float:left;">
        <el-form :inline="true" :model="filters" :size="global.gSize">
          <el-form-item>
            <el-input v-model="filters.urlName" :placeholder="'路径'"></el-input>
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-search" :label="$t('action.search')" perms="sys:log:view" type="primary"
              @click="findPage(null)" />
          </el-form-item>
        </el-form>
      </div>
    </div>



    <div class="gk-layout-main">
      <my-table :data="pageResult.content" :loading="loading"  >
          <el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
            <template slot-scope="scope">   {{scope.$index+1}}   </template>
          </el-table-column> 
      
          <column  prop="ip" :label="$t('log.ip')"  />
          <column prop="urlName" :label="$t('log.urlName')"    />
          <column  prop="user" :label="$t('log.user')"  />
          <column prop="time" :label="$t('log.dt')"   />

          <el-table-column  header-align="center"  align="center"    :label="$t('action.operation')" >
              <template slot-scope="scope">
                <kt-button icon="fa fa-edit"  :label="$t('action.edit')"  perms="mes:lm"    @click="handleEdit(scope.$index, scope.row)" />
              </template>
          </el-table-column>
      </my-table>
  </div>
  <!--分页栏-->
  <div class="toolbar gk-layout-footer"  style="padding:10px;">

    <el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
                   :current-page="pageRequest.pageNum"
                   :page-size="pageRequest.pageSize"
                   :total="pageResult.totalSize"
                   style="float:right;">
    </el-pagination>
  </div>


    <!--新增编辑界面-->
    <el-dialog title="查看日志" width="70%" :visible.sync="dialogVisible"
      :close-on-click-modal="false">
      <el-form :model="dataForm" label-width="70px" :rules="dataFormRules" ref="dataForm" :size="global.gSize"
        label-position="right">


        <el-row>
          <el-col :span="12">

            <el-form-item :label="'用户'" prop="user">
              <el-input v-model="dataForm.user" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'路径'" prop="urlName">
              <el-input v-model="dataForm.urlName" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="'参数'" prop="param">
              <el-input type="textarea" v-model="dataForm.param" :rows="8" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="'结果'" prop="result">
              <el-input type="textarea" v-model="dataForm.result" :rows="10" auto-complete="off"></el-input>
            </el-form-item>

          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="'时间'" prop="dt">
              <el-input v-model="dataForm.time" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'ip'" prop="ip">
              <el-input v-model="dataForm.ip" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="global.gSize" @click.native="dialogVisible = false">{{'确认'}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

  import KtButton from "@/views/Core/KtButton"
  import { format } from "@/utils/datetime"
import MyTable from "@/views/Core/MyTable"
import Column from "@/views/Core/Column"
import { formatJson2taxtArea } from "@/utils/myUtil"
  export default {
    components: {
 MyTable,Column,
      KtButton
    },
    data() {
      return {
 
        filters: {
          name: ''
        },
    
        filterColumns: [],
        pageRequest: { pageNum: 1, pageSize: 20 },
        operation: false, // true:新增, false:编辑
        dialogVisible: false, // 新增编辑界面是否显示
        editLoading: false,
        dataForm: {
          id: 0,
          name: '',
          type: '',
          code: ''
        },
        filters: {
          name: ''
        },
        myButtons: [{
          name: "handleEdit",
          perms: "core:receiptout:edit",
          label: "查看",
          icon: "fa fa-edit"
        }],
       
        pageResult: {},
        showOperation: true
      }
    },
    computed: {
      dataFormRules() {
        const dataFormRules = {
          name: [{ required: true, message: this.getKey("user.userInput"), trigger: 'blur' }]
        };
        return dataFormRules;
      }
    },
    methods: {
      // 获取分页数据
      findPage: function (data) {
        if (data !== null) {
          this.filters.pageNum = data
        } else {
          this.filters.pageNum = 1
        }
        this.filters.pageSize = this.pageRequest.pageSize
        this.$api.log.findPage(this.filters).then((res) => {
          this.pageResult = res.data

        })
      },
      // 显示编辑界面
      handleEdit: function (params,row) {

        this.dialogVisible = true
        this.operation = false
        var data = Object.assign({}, row);
        data.result = formatJson2taxtArea(data.result);
        this.dataForm = data



      } ,
      submitForm: function () {
        window.close();
      },
      getKey: function (arg) {
        return this.$t(arg)
      },
      // 时间格式化
      dateFormat: function (row, column, cellValue, index) {
        return format(row[column.property])
      }
    },
    mounted() {
    	this.findPage(null)
  
    }
  }
</script>
